-- ==== BEGIN LICENSE BLOCK ====
-- storyboard-addon - Copyright (C) Arnaud Charnoz, 2006-2010.
-- Distributed under the terms of the GNU Lesser General Public License (LGPL) as
-- published by the Free Software Foundation.
-- ===== END LICENSE BLOCK ====

 
Storyline = {};
 
Storyline.__index = Storyline;

function Storyline:new()
    
    local self = {};
    setmetatable(self, Storyline);

    self.versionData = 1;
    
    self.title = "MyTitle";
    self.numericVersion = 1;
    self.textVersion = "1.00 beta Fr 04/03/2006";
    self.authorA = "Makao, La Croisade Ecarlate (FR)";
    self.authorB = "Toto, LCE (FR)";
    self.authorC = "Titi, KT (FR)";
    self.password = "MyPassword";
    self.factionRequirement = "none";
    self.levelRequirement = "level 10 minimun";
    self.otherRequirements = "none";
    self.abstract = "bla bla bla bla bla";
    self.starter = "bla bla bla bla bla";
    
    self.locationDB = LocationDB:new();
       
    return self;
end

-------------------------------------------------------------------------------

function Storyline:sharedCopy( fromObj )

    self.title = fromObj.title;
    self.numericVersion = fromObj.numericVersion;
    self.textVersion = fromObj.textVersion;
    self.authorA = fromObj.authorA;
    self.authorB = fromObj.authorB;
    self.authorC = fromObj.authorC;
    self.password = fromObj.password;
    self.factionRequirement = fromObj.factionRequirement;
    self.levelRequirement = fromObj.levelRequirement;
    self.otherRequirements = fromObj.otherRequirements;
    self.abstract = fromObj.abstract;
    self.starter =  fromObj.starter;

    self.locationDB = fromObj.locationDB;
  
end

-------------------------------------------------------------------------------

function Storyline:reset()
    
    newStoryline = Storyline:new();
    self:sharedCopy( newStoryline );
    
   --self.locationDB = LocationDB:new();
    --self.title = "Unknow";
    --self.numericVersion = "1";
    --self.textVersion = "1 Fr xx/xx/2010";
    --self.authors = "Makao, La Croisade Ecarlate (FR)";
   -- self.password = "MyPassword";
   -- self.factionRequirement = "none";
   -- self.levelRequirement = "level 10 minimun";
   -- self.otherRequirement = "none";
   -- self.abstract = "bla bla bla bla bla";
    --self.starter = "bla bla bla bla bla";
    
end

function Storyline:getId()
    return ( self.title .. " (v" .. self.numericVersion .. ")" );
end

function Storyline:setTitle( newTitle )
    self.title = newTitle;
end

function Storyline:setNumericVersion( newNumericVersion)
    self.numericVersion = newNumericVersion;
end

function Storyline:setTextVersion( newTextVersion )
    self.textVersion = newTextVersion;
end

function Storyline:setAuthorA( newAuthorA )
    self.authorA = newAuthorA;
end

function Storyline:setAuthorB( newAuthorB )
    self.authorB = newAuthorB;
end

function Storyline:setAuthorC( newAuthorC )
    self.authorC = newAuthorC;
end

function Storyline:setPassword( newPassword )
    self.password = newPassword;
end

function Storyline:setFactionRequirement( newFactionRequirement )
    self.factionRequirement= newFactionRequirement;
end

function Storyline:setOtherRequirements( newOtherRequirements )
    self.otherRequirements= newOtherRequirements;
end

function Storyline:setLevelRequirement( newLevelRequirement )
    self.levelRequirement= newLevelRequirement;
end

function Storyline:setAbstract( newAbstract )
    self.abstract= newAbstract;
end

function Storyline:setStarter( newStarter )
    self.starter= newStarter;
end



function Storyline:getTitle()
    return self.title;
end

function Storyline:getNumericVersion()
    return self.numericVersion;
end

function Storyline:getTextVersion()
    return self.textVersion;
end

function Storyline:getAuthorA()
    return self.authorA;
end

function Storyline:getAuthorB()
    return self.authorB;
end

function Storyline:getAuthorC()
    return self.authorC;
end

function Storyline:getPassword()
    return self.password;
end

function Storyline:getFactionRequirement()
    return self.factionRequirement;
end

function Storyline:getOtherRequirements()
    return self.otherRequirements;
end

function Storyline:getLevelRequirement()
    return self.levelRequirement;
end

function Storyline:getAbstract()
    return self.abstract;
end

function Storyline:getStarter()
    return self.starter;
end

    
    

function Storyline:exportToString()

    local dataTable = {} ;
    
    table.insert( dataTable, self.title );
    table.insert( dataTable, self.numericVersion );
    table.insert( dataTable, self.textVersion );
    table.insert( dataTable, self.authorA );
    table.insert( dataTable, self.authorB );
    table.insert( dataTable, self.authorC );
    table.insert( dataTable, self.password );
    table.insert( dataTable, self.factionRequirement );
    table.insert( dataTable, self.levelRequirement );
    table.insert( dataTable, self.otherRequirements );
    table.insert( dataTable, self.abstract );
    table.insert( dataTable, self.starter );
    table.insert( dataTable, self.locationDB:exportToTable() );

    dataTable.versionData = 1;
    
    local dataString = StoryBoard:Serialize( dataTable );
    
    return dataString;
    
end


function Storyline:importFromString( dataString )

    local dataTable = {} ;
    
    success, dataTable = StoryBoard:Deserialize( dataString );

    if success
    then

        if ( dataTable.versionData ~= nil and dataTable.versionData == self.versionData )
        then
        
            self.title = dataTable[1];
            self.numericVersion = dataTable[2];
            self.textVersion = dataTable[3];
            self.authorA = dataTable[4];
            self.authorB = dataTable[5];
            self.authorC = dataTable[6];
            self.password = dataTable[7];
            self.factionRequirement = dataTable[8];
            self.levelRequirement = dataTable[9];
            self.otherRequirements = dataTable[10];
            self.abstract = dataTable[11];
            self.starter = dataTable[12];
            self.locationDB:importFromTable ( dataTable[13] );

        else
        
            SBMessageManager:debugMessage("Le format de cette sauvegarde n'est pas compatible avec la version actuelle de StoryBoard");
            
        end
        
    else
    
        SBMessageManager:debugMessage("Impossible de deserialiser cette chaine de caractere");
    
    end
    
end